package com.gel.shortLink.admin.remote.service;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.TypeReference;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gel.shortLink.admin.convention.result.Result;
import com.gel.shortLink.admin.remote.dto.req.*;
import com.gel.shortLink.admin.remote.dto.resp.ShortLinkCreateRespDTO;
import com.gel.shortLink.admin.remote.dto.resp.ShortLinkGroupCountQueryRespDTO;
import com.gel.shortLink.admin.remote.dto.resp.ShortLinkPageRespDTO;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
public interface ShortLinkRemoteService {
    /*创建短链接*/
    default Result<ShortLinkCreateRespDTO> createShortLink(ShortLinkCreateReqDTO requestParam){
        String resultStr = HttpUtil.post("http://127.0.0.1:8001/api/short-link/project/link/create", JSON.toJSONString(requestParam));
        return JSON.parseObject(resultStr, new TypeReference<Result<ShortLinkCreateRespDTO>>(){});
    }
    /*分页查询*/
    default Result<IPage<ShortLinkPageRespDTO>> pageShortLink(ShortLinkPageReqDTO requestParam) {
        Map<String, Object> map=new HashMap<>();
        map.put("current", requestParam.getCurrent());
        map.put("size", requestParam.getSize());
        map.put("gid", requestParam.getGid());
        map.put("orderTag",requestParam.getOrderTag());
        String resultStr = HttpUtil.get("http://127.0.0.1:8001/api/short-link/project/link/page", map);
        return JSON.parseObject(resultStr, new TypeReference<Result<IPage<ShortLinkPageRespDTO>>>(){});
    }
    /*查询分组下的短连接数量*/
    default Result<List<ShortLinkGroupCountQueryRespDTO>> listGroupShortLinkCount(List<String> requestParam) {
        Map<String, Object> map=new HashMap<>();
        map.put("requestParam", requestParam);
        String resultStr = HttpUtil.get("http://127.0.0.1:8001/api/short-link/project/link/list", map);
        return JSON.parseObject(resultStr, new TypeReference<Result<List<ShortLinkGroupCountQueryRespDTO>>>(){});

    }
    /*保存至回收站*/
    default Result<Void> saveRecycle(RecycleBinSaveReqDTO requestParam) {
        String resultStr = HttpUtil.post("http://127.0.0.1:8001/api/short-link/project/link/recycle/save", JSON.toJSONString(requestParam));
        return JSON.parseObject(resultStr, new TypeReference<Result<Void>>(){});
    }
    /*分页查询回收站*/
    default Result<IPage<ShortLinkPageRespDTO>> pageRecycleShortLink(RecyclePageReqDTO requestParam) {
        Map<String, Object> map=new HashMap<>();
        map.put("current", requestParam.getCurrent());
        map.put("size", requestParam.getSize());
        map.put("gidList", requestParam.getGidList());
        String resultStr = HttpUtil.get("http://127.0.0.1:8001/api/short-link/project/link/recycle/page",map);
        return JSON.parseObject(resultStr, new TypeReference<Result<IPage<ShortLinkPageRespDTO>>>(){});
    }

    default Result<Void> recoverRecycle(RecycleBinRecoverReqDTO requestParam){
        String resultStr = HttpUtil.post("http://127.0.0.1:8001/api/short-link/project/link/recycle/recover", JSON.toJSONString(requestParam));
        return JSON.parseObject(resultStr, new TypeReference<Result<Void>>(){});
    }

    default Result<Void> removeRecycle(RecycleBinRemoveReqDTO requestParam){
        String resultStr = HttpUtil.post("http://127.0.0.1:8001/api/short-link/project/link/recycle/remove", JSON.toJSONString(requestParam));
        return JSON.parseObject(resultStr, new TypeReference<Result<Void>>(){});

    }
}
